import React from 'react'
import { Select } from 'antd'
const Option = Select.Option
export default {
    formatDate(time) {
        if (!time) return ''
        let date = new Date(time)
        return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDay()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
    },
    pagination(data, callback){
        return {
            onChange: (current) => {
                callback(current)
            },
            current:data.result.page,
            pageSize:data.result.pageSize,
            total:data.result.total,
            showTotal:()=>{
                return `共${data.result.total}条咸鱼`
            },
            showQuickJumper:true,
        }
    },
    getOptionList(data){
        let options  = []
        if(!data){
            return options
        }

        data.map((item) => {
            options.push(<Option value={item.id} key={item.id}>{item.name}</Option>)
        })
        return options;
    },
    updateSelectedItem(selectedRowKeys, selectedItem, selectedIds){
        if(selectedIds){
            this.setState({
                selectedRowKeys,
                selectedItem,
                selectedIds
            })
        } else {
            this.setState({
                selectedRowKeys,
                selectedItem,
            })
        }

    }
}
